package com.henanuniversity.service.impl;

import com.henanuniversity.dao.DeliveryAddressDao;
import com.henanuniversity.dao.impl.DeliveryAddressDaoImpl;
import com.henanuniversity.po.DeliveryAddress;
import com.henanuniversity.service.DeliveryAddressService;
import com.henanuniversity.utils.DBUtils;

import java.util.List;

public class DeliveryAddressServiceImpl implements DeliveryAddressService {
    @Override
    public List<DeliveryAddress> listDeliveryAddressByUserId(String userId) {
        DeliveryAddressDao dao=new DeliveryAddressDaoImpl();
        List<DeliveryAddress> list = dao.listDeliveryAddressByUserId(userId);
        DBUtils.close();
        return list;
    }

    @Override
    public int saveDeliveryAddress(DeliveryAddress deliveryAddress) {
        DeliveryAddressDao dao=new DeliveryAddressDaoImpl();
        int address = dao.saveDeliveryAddress(deliveryAddress);
        DBUtils.close();
        return address;
    }

    @Override
    public int removeDeliveryAddress(Integer daId) {
        DeliveryAddressDao dao=new DeliveryAddressDaoImpl();
        int result = dao.removeDeliveryAddress(daId);
        DBUtils.close();
        return result;
    }

    @Override
    public DeliveryAddress getDeliveryAddressById(Integer daId) {

        DeliveryAddressDao dao=new DeliveryAddressDaoImpl();
        DeliveryAddress deliveryAddress = dao.getDeliveryAddressById(daId);
        DBUtils.close();
        return deliveryAddress;
    }

    @Override
    public int updateDeliveryAddress(DeliveryAddress deliveryAddress) {
        DeliveryAddressDao dao=new DeliveryAddressDaoImpl();
        int result = dao.updateDeliveryAddress(deliveryAddress);
        DBUtils.close();
        return result;
    }
}
